package com.lanou3g.mynewstest.module.news.headline;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.widget.TextView;

import com.lanou3g.mynewstest.R;
import com.lanou3g.mynewstest.base.MyBaseActivity;
import com.lanou3g.mynewstest.beans.NewsDetailBeans;
import com.lanou3g.mynewstest.tools.URLImageGetter;

import static android.text.Html.fromHtml;

/**
 * Created by dllo on 16/1/15.
 */
public class DetailActivity extends MyBaseActivity {
    private static Context context;
    private static NewsDetailBeans data;
    private TextView title, pTime, body;
    private String bodyText;


    public static void goToDetailActivity(Context context, NewsDetailBeans data) {
        DetailActivity.context = context;
        DetailActivity.data = data;
        Intent intent = new Intent(context, DetailActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        bodyText= data.getPostID().getBody();
        title = (TextView) findViewById(R.id.detail_title);
        pTime = (TextView) findViewById(R.id.detail_ptime);
        body = (TextView) findViewById(R.id.detail_body);
        title.setText(data.getPostID().getTitle());
        pTime.setText(data.getPostID().getSource() + "  " + data.getPostID().getPtime());
        for (int i = 0; i < data.getPostID().getImg().size(); i++) {
            String src=data.getPostID().getImg().get(i).getSrc();
            String alt=data.getPostID().getImg().get(i).getAlt();
            String ref=data.getPostID().getImg().get(i).getRef();
            bodyText=bodyText.replace(ref,"<img src=\""+src+"\"  alt=\""+alt+"\" />");


        }

        body.setMovementMethod(LinkMovementMethod.getInstance());
        URLImageGetter ReviewImgGetter = new URLImageGetter(context, body);//实例化URLImageGetter类
        body.setText(Html.fromHtml(bodyText,ReviewImgGetter,null));

    }


}
